package com.leetcode.May;

/**
 * @Description: 盛最多水的容器
 * @Author: Mr.Fxy
 * @CreateTime: 2024-05-12 09:33
 */
public class MaxWater {
    public static void main(String[] args) {
        System.out.println(maxArea(new int[]{2,3,4,5,18,17,6}));
    }

    public static int maxArea(int[] height) {
        int right=height.length-1;
        int left=0;
        int max=0;
        while(left<right){
             max=Math.max(max,Math.min(height[left],height[right])*(right-left));
             if (height[left]<height[right]){
                 left++;
            }else {
                 right--;
             }
        }
        return max;
    }
//              暴力解法
//    public static int maxArea(int[] height) {
//        int max = 0;
//        for (int i = 0; i < height.length; i++) {
//            for (int j = i + 1; j < height.length; j++) {
//                max = Math.max(max, Math.min(height[i], height[j] )* (j - i));
//            }
//        }
//        return max;
//    }
}
